define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'progress/index',
                    add_url: 'progress/add',
                    edit_url: 'progress/edit',
                    del_url: 'progress/del',
                    multi_url: 'progress/multi',
                    table: 'progress',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'progress_type', title: __('Progress_type'), visible:false, searchList: {"1":__('Progress_type 1')}},
                        {field: 'progress_type_text', title: __('Progress_type'), operate:false},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user_name', title: __('User_name')},
                        {field: 'site_id', title: __('Site_id')},
                        {field: 'progress_building', title: __('Progress_building')},
                        {field: 'progress_unit', title: __('Progress_unit')},
                        {field: 'progress_quantities', title: __('Progress_quantities')},
                        {field: 'progress_unitprice', title: __('Progress_unitprice')},
                        {field: 'progress_amount', title: __('Progress_amount')},
                        {field: 'progress_completions', title: __('Progress_completions')},
                        {field: 'progress_subtotal', title: __('Progress_subtotal')},
                        {field: 'progress_attribute', title: __('Progress_attribute')},
                        {field: 'progress_tj_user_id', title: __('Progress_tj_user_id')},
                        {field: 'progress_tj_user_name', title: __('Progress_tj_user_name')},
                        {field: 'progress_submit_time', title: __('Progress_submit_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'progress_add_time', title: __('Progress_add_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'progress_status', title: __('Progress_status'), visible:false, searchList: {"1":__('Progress_status 1')}},
                        {field: 'progress_status_text', title: __('Progress_status'), operate:false},
                        {field: 'progress_flag', title: __('Progress_flag'), searchList: {"2":__('Progress_flag 2')}, formatter: Table.api.formatter.flag},
                        {field: 'last_update_user_id', title: __('Last_update_user_id')},
                        {field: 'last_update_user_name', title: __('Last_update_user_name')},
                        {field: 'last_update_time', title: __('Last_update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});